const exec = require('child_process').exec
const styles = require('./styles')

module.exports = {
  exec: (command, pause) => {
    return new Promise((reslove, reject) => {
      if (!pause) {
        console.log(styles.magentaBG, '$ ' + command)
      }
      exec(command, { encoding: 'utf-8' }, (err, stdout, stderr) => {
        if (err) {
          console.error(styles.red, err)
          reject(err)
        } else {
          console.log(styles.green, stdout)
          reslove(stdout)
        }
      })
    })
  }
}